// pages/new-pages/scan-hint/scan-hint.js
const app = getApp()
import Toast from '../../../component/toast/toast';
Page({

    /**
     * 页面的初始数据
     */
    data: {
        authChecked:false,
        resumeId:''
    },

    checkboxChange(e){
        this.setData({
            authChecked: !this.data.authChecked
        })
    },
    openScan(){
        let that = this;
        wx.scanCode({
            success(res) {
                let result = res.result.substr(4);
                console.log(result)
                wx.request({
                    url: app.globalData.serverAddress.updateLoginQRCode,
                    data: {
                        Id: result,
                        UserInfoId: app.userInfo.Id,
                        ExtField: that.data.resumeId
                    },
                    header: {
                        'Authorization': "Bearer " + app.globalData.token
                    },
                    method: 'POST',
                    success: function (res) {
                        console.log('updateLoginQRCode response', res);
                        Toast(res.data.Message);
                        if (res.statusCode == 200) {
                            if (res.data.CodeStatus == 20000) {
                                wx.navigateBack({ delta: 1})
                            }
                        }
                    },
                    fail: function (res) {
                        console.log("updateLoginQRCode fail", res)
                        Toast('扫码失败，请重新扫码')
                    },
                    complete: function (res) {
                        wx.hideLoading();
                    },
                })
                try {
                    wx.setStorageSync('no_hint_scan', that.data.authChecked)
                } catch (e) { }
            }
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        this.setData({
            resumeId: options.resumeId
        })
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})